//
//  LiquorlistController.m
//  LiquorChain
//
//  Created by apple on 2018/12/24.
//  Copyright © 2018年 王冬. All rights reserved.
//

#import "LiquorlistController.h"
#import "StrategyController.h"
#import "LiquorViewCell.h"
#import "MenuHeaderView.h"
@interface LiquorlistController ()<UITableViewDelegate,UITableViewDataSource,MenuHeaderViewDelegate>{
   
}
@property (nonatomic,strong) UITableView *tableView;
@end

@implementation LiquorlistController
{
    NSInteger _currentMenuIndex;
}
static NSString *CellIdentifier = @"liqCell";
- (void)viewDidLoad {
    [super viewDidLoad];
    
 
    self.navigationItem.title = @"圣酒记录";
    self.view.backgroundColor =[UIColor whiteColor];
    self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, kNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT - kNavBarHeight- kIPhoneXBottomHeight) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
   // [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
    [self.tableView registerNib:[UINib nibWithNibName:@"LiquorViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self.view addSubview:self.tableView];
   
    [self creatHeadView];
    _currentMenuIndex = 0;
    // Do any additional setup after loading the view.
}


-(void)creatHeadView{
    UIView *headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 220)];
    headView.backgroundColor =[UIColor whiteColor];
    UIView *topView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
    topView.backgroundColor = RGBA(16.0, 0.0, 52.0, 1);
    UILabel *showLabel =[[UILabel alloc]init];
    [topView addSubview:showLabel];
    showLabel.text = @"可用圣酒";
    showLabel.textColor = [UIColor whiteColor];
    showLabel.font =[UIFont systemFontOfSize:12];
    [showLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(21);
        make.left.mas_equalTo(14);
        make.height.mas_equalTo(12);
    }];
    //
    UILabel *showNumber =[[UILabel alloc]init];
    [topView addSubview:showNumber];
    showNumber.textColor =[UIColor whiteColor];
    showNumber.text =@"0.00001";
    showNumber.font = [UIFont systemFontOfSize:30];
    [showNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.top.mas_equalTo(40);
        make.height.mas_equalTo(23);
    }];
    // 昨日圣酒
    UILabel *oldLabel =[[UILabel alloc]init];
    [topView addSubview:oldLabel];
    oldLabel.textColor = [UIColor whiteColor];
    oldLabel.font = [UIFont systemFontOfSize:12];
    oldLabel.text = [NSString stringWithFormat:@"昨日:%f",0.12];
    [oldLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left .mas_equalTo(14);
        make.top.mas_equalTo(71);
        make.height.mas_equalTo(12);
    }];
    UILabel *infoLabel =[[UILabel alloc]init];
    [topView addSubview:infoLabel];
    infoLabel.textColor =[UIColor whiteColor];
    infoLabel.font =[UIFont systemFontOfSize:12];
    infoLabel.text = @"圣酒是依托于区块链技术，基于酿酒师在酒链世界活动数据产生的奖励，形成的数字资产，可以用于酒链世界上的消费、兑换等。";
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:infoLabel.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
    [paragraphStyle setLineSpacing:10];//调整行间距
    
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [infoLabel.text length])];
    infoLabel.attributedText = attributedString;
    [infoLabel sizeToFit];
    
    
    infoLabel.numberOfLines = 0;
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.right.mas_equalTo(-14);
        make.top.mas_equalTo(110);
    }];
    
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [topView addSubview:rightBtn];
    [rightBtn setBackgroundColor:[UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.3]];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(40);
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(30);
    }];
    rightBtn.layer.cornerRadius = 15;
    [rightBtn setTitle:@"圣酒攻略" forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:@"rightj"] forState:UIControlStateNormal];
    [rightBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:4];
    [rightBtn setTitleColor:[UIColor whiteColor]
                   forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
    
    MenuHeaderView *titleView =[[MenuHeaderView alloc]initWithFrame:CGRectMake(0, 170, SCREEN_WIDTH, 50)];
    [headView addSubview:titleView];
    titleView.backgroundColor = [UIColor whiteColor];
    titleView.items = @[@"日常",@"谢师酒",@"交易",@"兑换",@"赠送",@"推荐",@"其他"].mutableCopy;
    titleView.delegate = self;
    titleView.currentIndex = _currentMenuIndex;
//    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(170);
//        make.height.mas_equalTo (50);
//        make.left.right.mas_equalTo(0);
//    }];
  
    
    [headView addSubview:topView];
  
    self.tableView.tableHeaderView = headView;
}
-(void)rightClick:(UIButton *)sender{
    StrategyController *strVC =[[StrategyController alloc]init];
    strVC.titleStr = sender.titleLabel.text;
    [self.navigationController pushViewController:strVC animated:YES];
    
}

// 分类代理
- (void)menuView:(MenuHeaderView *)menuView didSelectItem:(NSInteger)index
{
    // 网络请求第 index个；
    NSLog(@"%@",menuView.itemsID[index]);
    _currentMenuIndex = index;
    [self.tableView reloadData];

}
#pragma mark
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LiquorViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%ld",indexPath.row);
}
@end
